package com.andy.nature.ui.activity

import android.view.MotionEvent
import android.widget.LinearLayout
import com.andy.common.base.BaseVMActivity
import com.andy.common.extend.hideKeyboard
import com.andy.nature.databinding.ActivityKeyboardBinding
import com.andy.nature.view.KeyBoardLayout
import com.andy.nature.vm.CommonViewModel

/**
 * Author:Andy
 * Date:2023/3/20 17:51
 * Description:KeyboardActivity
 */
class KeyboardActivity : BaseVMActivity<ActivityKeyboardBinding, CommonViewModel>(), KeyBoardLayout.ImeStateListener {

    override fun viewModelClass(): Class<CommonViewModel> {
        return CommonViewModel::class.java
    }

    override fun getViewBinding(): ActivityKeyboardBinding {
        return ActivityKeyboardBinding.inflate(layoutInflater)
    }

    override fun initObserve() {

    }

    override fun initData() {
        mBinding?.apply {
            rootView.setImeListener(this@KeyboardActivity)
        }
    }

    override fun initAction() {
        mBinding?.apply {
            rvList.setOnTouchListener { _, event ->
                if (event.action == MotionEvent.ACTION_DOWN) {
                    rvList.hideKeyboard(0)
                }
                false
            }
            vTitle.setClickLeftCallBack {
                finish()
            }
        }
    }

    override fun onImeBottomChanged(height: Int) {
    }

    override fun onImeFixNavigationBarBottomChanged(height: Int) {
        mBinding?.apply {
            val lp = clInputPanel.layoutParams as LinearLayout.LayoutParams
            lp.bottomMargin = height
            clInputPanel.layoutParams = lp
        }
    }

    override fun onImeClose() {
    }
}